package com.cogent.report;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;

import com.cogent.common.util.MapUtil;
import com.cogent.report.domain.ReportDomain;
import com.cogent.report.facade.IReportFacade;

public class ReportUtil {
	private static Logger _log = Logger.getLogger(ReportUtil.class);

	public static HashMap loadQueryMap(ReportDomain reportDomain,
			IReportFacade reportFacade, String username, HashMap formMap,
			String repid) {
		ReportStream rstream = new ReportStream();
		HashMap queryformmap = new HashMap();
		if (rstream.isFileExist(username)) {
			ReportSetting rset;
			try {
				rset = rstream.readStream(username);
				Map mapset = rset.getMap();
				if (mapset.containsKey(repid))
					queryformmap = (HashMap) mapset.get(repid);
			} catch (Exception e) {
				_log.error(e);
			}
		}
		if (queryformmap.size() == 0)
			queryformmap.put("districtcode", MapUtil.getStringValue(formMap,
					"districtcode"));

		return queryformmap;
	}

	public static String[] listToArray(List list) {
		String[] ret = new String[list.size()];
		for (int i = 0; i < list.size(); i++)
			ret[i] = list.get(i).toString();

		return ret;
	}

}
